<template>
	<view class="fui-wrap">
		<view class="userinfo">
			<image :src="userinfo.avatar" mode="widthFix" style="width: 200rpx;"></image>
			<text>{{userinfo.nickname}}</text>
		</view>
		<fui-form labelColor="#7a7a7a" ref="form" top="0" :model="formData" :show="false">
			<fui-form-item label="用户名">
				<fui-input readonly :borderBottom="false" :padding="[0]" :value="formData.username">
					<fui-button text="复制" @click="copy" :size="24" background="#fff" color="#43afe8" borderColor="#43afe8" width="80rpx" height="40rpx"></fui-button>
				</fui-input>
			</fui-form-item>
			<fui-form-item label="姓名">
				<fui-input readonly :borderBottom="false" :padding="[0]" :value="formData.nickname"></fui-input>
			</fui-form-item>
			<fui-form-item label="密码" prop="password">
				<fui-input type="password" :borderBottom="false" :padding="[0]" placeholder="请输入密码" v-model="formData.password"></fui-input>
			</fui-form-item>
			<fui-form-item label="重复密码" prop="rpassword">
				<fui-input type="password" :borderBottom="false" :padding="[0]" placeholder="请再次输入密码" v-model="formData.rpassword"></fui-input>
			</fui-form-item>
			<view class="fui-btn__box">
				<fui-button :disabled="disabledButton" text="提交" bold @click="submit"></fui-button>
			</view>
		</fui-form>
	</view>
</template>

<script>
	import {methods,baseUrl} from '@/utils/core.js';
	export default {
		data() {
			return {
				userinfo:'',
				formData:{
					username:'',
					nickname:'',
					password:'',
					rpassword:''
				},
				disabledButton:false
			}
		},
		onLoad(e) {
			this.userinfo=this.$userinfo();
			this.$get('parking/index/parking-admin').then(res=>{
				this.formData.nickname=res.nickname;
				this.formData.username=res.username;
			});
		},
		methods: {
			...methods,
			copy:function(){
				uni.setClipboardData({
					data:this.formData.username
				});
			},
			submit:function(){
				let rules=[
					{
						name: "password",
						rule: ["required"],
						msg: ["请输入密码"]
					},
					{
						name: "rpassword",
						rule: ["required","isSame:password"],
						msg: ["请重复输入密码","两次密码不一致"]
					}
				];
				this.disabledButton=true;
				this.$refs.form.clearValidate();
				this.$refs.form.validator(this.formData,rules,true).then(res => {
					if (res.isPassed) {
						this.$post('parking/index/change-password',this.formData,true,true).then(res=>{
							this.$navigateBack(1500);
						}).catch(err=>{
							this.disabledButton=false;
						});
					}else{
						this.disabledButton=false;
					}
				}).catch(err => {
					this.disabledButton=false;
				});
			},
			
		}
	}
</script>

<style lang="scss" scoped>
.userinfo{
	display: flex;
	flex-direction: column;
	justify-content: center;
	align-items: center;
	height: 400rpx;
	image{
		border-radius: 50%;
	}
	text{
		margin-top: 20rpx;
	}
}
.fui-btn__box{
	padding: 20rpx;
}
</style>